0x01 A a^b
link
板子希望考场上不会忘
十年 OI 一场空,不开 ll 见祖宗。
#include <bits/stdc++.h>
using ll = long long;
auto main()->int {
// std::cin.tie(nullptr)->sync_with_stdio(false);
ll A, B, P;
std::cin >> A >> B >> P;
auto power = [&](ll a, ll b, ll p) {
ll ans = 1 % p;
for (; b; b >>= 1) {
if (b & 1) ans = ans * a % p;
a = a * a % p;
}
return a == 0 ? 0 : ans;
};
ll res = power(A, B, P);
printf("%lld^%lld mod %lld=%lld", A, B, P, res);
return 0;
}
7min (Luogu) (Nowcoder)